import 'package:flutter_uxin/Tools/config/commonTool.dart';

class commonAddressBook {
  List<Groups> groups;

  commonAddressBook({this.groups});

  commonAddressBook.fromJson(Map<String, dynamic> json) {
    if (json['groups'] != null) {
      groups = new List<Groups>();
      json['groups'].forEach((v) {
        groups.add(new Groups.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.groups != null) {
      data['groups'] = this.groups.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Groups {
  String setName;
  String membersCount;
  String name;
  String classId;
  String createdAt;
  String teacherInCharge;
  String gradeId;
  String schoolId;
  String yjtGroupId;
  String creatorId;
  List<Members> members;
  String save;
  String id;
  String groupType;

  Groups(
      {this.setName,
      this.membersCount,
      this.name,
      this.classId,
      this.createdAt,
      this.teacherInCharge,
      this.gradeId,
      this.schoolId,
      this.yjtGroupId,
      this.creatorId,
      this.members,
      this.save,
      this.id,
      this.groupType});

  Groups.fromJson(Map<String, dynamic> json) {
    setName = json['set_name'];
    membersCount = json['members_count'];
    name = json['name'];
    classId = json['class_id'];
    createdAt = json['created_at'];
    teacherInCharge = json['teacher_in_charge'];
    gradeId = json['grade_id'];
    schoolId = json['school_id'];
    yjtGroupId = json['yjt_group_id'];
    creatorId = json['creator_id'];
    if (json['members'] != null) {
      members = new List<Members>();
      json['members'].forEach((v) {
        members.add(new Members.fromJson(v));
      });
    }
    save = json['save'];
    id = json['id'];
    groupType = json['group_type'];
  }

  Groups.fromDBJson(Map<String, dynamic> json) {
    setName = json['setName'];
    membersCount = json['membersCount'];
    name = json['name'];
    classId = json['classId'];
    createdAt = json['createdAt'];
    teacherInCharge = json['teacherInCharge'];
    gradeId = json['gradeId'];
    schoolId = json['schoolId'];
    yjtGroupId = json['yjtGroupId'];
    creatorId = json['creatorId'];
    save = json['save'];
    id = json['GroupID'];
    groupType = json['groupType'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['set_name'] = this.setName;
    data['members_count'] = this.membersCount;
    data['name'] = this.name;
    data['class_id'] = this.classId;
    data['created_at'] = this.createdAt;
    data['teacher_in_charge'] = this.teacherInCharge;
    data['grade_id'] = this.gradeId;
    data['school_id'] = this.schoolId;
    data['yjt_group_id'] = this.yjtGroupId;
    data['creator_id'] = this.creatorId;
    if (this.members != null) {
      data['members'] = this.members.map((v) => v.toJson()).toList();
    }
    data['save'] = this.save;
    data['id'] = this.id;
    data['group_type'] = this.groupType;
    return data;
  }
}

class Members {
  String save;
  String name;
  String mobile;
  String pinyin;
  String quanpin;
  int userType;
  String sign;
  String schoolId;
  bool flagOfUpdating;
  String post;
  String realName;
  String id;
  String headerImageUrl;

  Members(
      {this.save,
      this.name,
      this.mobile,
      this.pinyin,
      this.quanpin,
      this.userType,
      this.sign,
      this.schoolId,
      this.flagOfUpdating,
      this.post,
      this.realName,
      this.id,
      this.headerImageUrl});

  Members.fromJson(Map<String, dynamic> json) {
    save = json['save'];
    name = json['name'];
    mobile = json['mobile'];
    pinyin = json['pinyin'];
    quanpin = json['quanpin'];
    userType = json['user_type'];
    sign = json['sign'];
    schoolId = json['school_id'];


    flagOfUpdating = commonTool.changeValueToBool(json['flag_of_updating']);


    post = json['post'];
    realName = json['real_name'];
    id = json['id'];
    headerImageUrl = json['header_image_url'];
  }

  Members.fromDBJson(Map<String, dynamic> json) {
    save = json['save'];
    name = json['name'];
    mobile = json['mobile'];
    pinyin = json['pinyin'];
    quanpin = json['quanpin'];

//    if (json['flagOfUpdating'] is int) {
//      userType = json['flagOfUpdating'];
//    }else if (json['flagOfUpdating'] is bool) {
//      userType = json['flagOfUpdating'];
//    }else{
//      userType = 0;
//    }
    userType = json['userType'];
    sign = json['sign'];
    schoolId = json['schoolId'];


    flagOfUpdating = commonTool.changeValueToBool(json['flag_of_updating']);

    post = json['post'];
    realName = json['realName'];
    id = json['UserID'];
    headerImageUrl = json['headerImageUrl'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['save'] = this.save;
    data['name'] = this.name;
    data['mobile'] = this.mobile;
    data['pinyin'] = this.pinyin;
    data['quanpin'] = this.quanpin;
    data['user_type'] = this.userType;
    data['sign'] = this.sign;
    data['school_id'] = this.schoolId;
    data['flag_of_updating'] = this.flagOfUpdating;
    data['post'] = this.post;
    data['real_name'] = this.realName;
    data['id'] = this.id;
    data['header_image_url'] = this.headerImageUrl;
    return data;
  }
}
